package com.hhp.cloud.shop.member.controller;

import java.util.Arrays;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hhp.cloud.shop.member.entity.IntegrationChangeHistoryEntity;
import com.hhp.cloud.shop.member.service.IntegrationChangeHistoryService;

import com.hhp.cloud.shop.common.core.result.R;



/**
 * 积分变化历史记录
 *
 * @author hhp
 * @email 2437579794@qq.com
 * @date 2021-11-24 16:26:44
 */
@RestController
@RequestMapping("/api/v1/member/integrationChangeHistory")
public class IntegrationChangeHistoryController {
    @Autowired
    private IntegrationChangeHistoryService integrationChangeHistoryService;

    /**
     * 列表
     */
    @ApiOperation(value = "积分变化历史记录分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "limit", value = "每页数量", paramType = "query", dataType = "Long"),
            @ApiImplicitParam(name = "memberId", value = "会员id", paramType = "query", dataType = "Long")
    })
    @GetMapping
    public R list(Integer page, Integer limit, Long memberId){
        return R.ok().put("data", integrationChangeHistoryService.pageMaps(
                new Page<>(page, limit),
                new LambdaQueryWrapper<IntegrationChangeHistoryEntity>()
                        .eq(ObjectUtil.isNotNull(memberId), IntegrationChangeHistoryEntity::getMemberId, memberId)));
    }


    /**
     * 信息
     */
    @ApiOperation(value = "积分变化历史记录详情")
    @ApiImplicitParam(name = "id", value = "积分变化历史记录id", required = true, paramType = "path", dataType = "Long")
    @GetMapping("/{id}")
    public R info(@PathVariable("id") Long id){
		return R.ok().setData(integrationChangeHistoryService.getById(id));
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增积分变化历史记录")
    @PostMapping
    public R save(@RequestBody IntegrationChangeHistoryEntity integrationChangeHistory){
		integrationChangeHistoryService.save(integrationChangeHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改积分变化历史记录")
    @PutMapping("/{id}")
    public R update(@PathVariable("id") Long id, @RequestBody IntegrationChangeHistoryEntity integrationChangeHistory){
		integrationChangeHistoryService.updateById(integrationChangeHistory);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除积分变化历史记录")
    @DeleteMapping
    public R delete(@RequestBody Long[] ids){
		integrationChangeHistoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
